import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ServersModule } from './servers/servers.module';
import { ScheduleModule } from '@nestjs/schedule';
import { DataGeneratorService } from './data-generator/data-generator.service';
import { DataGeneratorModule } from './data-generator/data-generator.module';
import { ProjectsModule } from './projects/projects.module';
import { AlertsModule } from './alerts/alerts.module';
import { LogsModule } from './logs/logs.module';
import { TopologyModule } from './topology/topology.module';
import { AnalyticsModule } from './analytics/analytics.module';
import { UserAnalyticsModule } from './user-analytics/user-analytics.module';
import { DashboardModule } from './dashboard/dashboard.module';
import { WebSocketsModule } from './web-sockets/web-sockets.module';
@Module({
  imports: [
    WebSocketsModule,
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST'),
        port: configService.get('DB_PORT'),
        username: configService.get('DB_USERNAME'),
        password: configService.get('DB_PASSWORD'),
        database: configService.get('DB_NAME'),
        autoLoadEntities: true, // 自动加载实体
        synchronize: configService.get('DB_SYNC') === 'true', // 开发环境同步
        logging: true, // 开启SQL日志
      }),
    }),
    ScheduleModule.forRoot(),
    ServersModule,
    DataGeneratorModule,
    ProjectsModule,
    AlertsModule,
    LogsModule,
    TopologyModule,
    AnalyticsModule,
    UserAnalyticsModule,
    DashboardModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
